package single.demo02;

/**
 * 饿汉式（静态代码块）
 *
 * 可能造成内存浪费
 *
 * instance在类装载的时候就实例化了
 *
 *
 */
public class Demo02 {

    public static void main(String[] args) {

        Single02 instance1 = Single02.getInstance();
        Single02 instance2 = Single02.getInstance();
        System.out.println(instance1 == instance2);
        System.out.println("hashCode1:"+instance1.hashCode());
        System.out.println("hashCode2:"+instance2.hashCode());

    }

}


class Single02{

    private Single02(){};

    private  final static Single02 instance;

    static{
        instance = new Single02();
    }

    public static Single02 getInstance(){
        return instance;
    }
}